home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / GAMES / P_ROBO31 / HIDNSEEK.PR < prev    next >
Text File  |  1989-10-30  |  4KB  |  93 lines

  1. (**************************************************************************)
  2. (*                             W A R N I N G                              *)
  3. (*                                                                        *)
  4. (*  This Robot has NOT been designed to take advantage of the advanced    *)
  5. (*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
  6. (**************************************************************************)
  7.  
  8. {   Pascal Robot "HIDNSEEK.PR"                             Don Lefebvre
  9.  
  10.     Strategy: This robot has two modes: a "hunting" mode in which it
  11.               pursues the opponent robot, and a "sparing" mode in which
  12.               it circles the opponent robot.  At game start, the opponent
  13.               is found and scanned twice.  If it is approaching then it
  14.               is assumed to be a hunter and the sparing mode is used,
  15.               otherwise the hunting mode is used.
  16.  
  17.     Hunting:  - Use range to determine whether opponent is advancing
  18.                 or receding and adjust range accordingly, then shoot.
  19.               - Move directly at the opponent at spped proportional
  20.                 to range (slows at close range).
  21.  
  22.     Sparing:  - Move at right angles to advancing hunter robot.
  23.               - Shoot without adjusting range.
  24. }
  25.   PROCEDURE hidnseek;
  26.   CONST
  27.     check = 3;                    { wait time for checking opponent       }
  28.     tol = 20;                     { tolerance for checking advancing opp. }
  29.     ang_adj = 95;                 { offset from heading for sparing robot }
  30.     adv_A = 0.85;                 { undershoot if opponent is advancing   }
  31.     rec_A = 1.22;                 { overshhot if opponent is receding     }
  32.  
  33.   VAR
  34.     cnt : Integer;                { number of cycles since last check     }
  35.     switch : Integer;             { flag indicating robot mode in effect  }
  36.     head : Integer;               { heading toward opponent robot         }
  37.     range : Integer;              { uncorrected range reported by scan    }
  38.     old_rng : Integer;            { range from previous scan              }
  39.     corr_rng : Real;              { range corrected for opponent's move   }
  40.     rng1 : Integer;               { save first range check                }
  41.     hd1 : Integer;                { save first heading check              }
  42.  
  43.  
  44.   BEGIN
  45.     switch := 2;                  { initialize variables }
  46.     cnt := 0;
  47.  
  48.     REPEAT
  49.       range := SCAN(head, 10);    { check old position  }
  50.  
  51.       IF (range = 0) THEN BEGIN
  52.         head := head-30;          { back up scan a bit  }
  53.         REPEAT
  54.           head := head+20;
  55.           range := SCAN(head, 10);
  56.         UNTIL (range <> 0);       { scan until find opp.}
  57.       END;
  58.  
  59.       CASE switch OF
  60.         0 : BEGIN                 { "sparing" mode      }
  61.               CANNON(head, range);
  62.               IF ((Abs(loc_x-500) > 400) OR (Abs(loc_y-500) > 400))
  63.               THEN DRIVE(Angle_To(500, 500), 100)
  64.               ELSE DRIVE((head+ang_adj) MOD 360, 100);
  65.             END;
  66.         1 : BEGIN                 { "hunting" mode      }
  67.               IF (range < old_rng)
  68.               THEN corr_rng := range*adv_A
  69.               ELSE corr_rng := range*rec_A;
  70.               CANNON(head+4, corr_rng);
  71.               old_rng := range;
  72.               CANNON(head-4, corr_rng);
  73.               DRIVE(head, range DIV 2);
  74.             END;
  75.         2 : BEGIN                 { first range check   }
  76.               CANNON(head, range);
  77.               cnt := cnt+1;
  78.               IF (cnt > check) THEN BEGIN
  79.                 rng1 := range;
  80.                 hd1 := head;
  81.                 switch := 3;
  82.               END;
  83.             END;
  84.         3 : BEGIN                 { second range check  }
  85.               IF ((range-rng1 < -tol) AND (Abs(head-hd1) < 10))
  86.               THEN switch := 0
  87.               ELSE switch := 1;
  88.             END;
  89.       END;
  90.  
  91.     UNTIL DEAD OR WINNER;
  92.   END;
  93.